package com.yu.newsSys.utils;

import com.alibaba.fastjson2.JSON;
import com.yu.newsSys.vo.Result;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CommonUtils {
    public static void printData(Result result, HttpServletResponse resp) throws IOException {
        String resultJsonString = JSON.toJSONString(result);
        resp.setContentType("text/html;charset=utf8");
        ServletOutputStream os = resp.getOutputStream();
        os.write(resultJsonString.getBytes("utf-8"));
    }

    public static void logInfo(String method,String layer,Object... objs) {
        System.out.printf("%s from %s is running!\n",method,layer);

        if (objs != null && objs.length > 0) {
            for (int i = 0; i < objs.length; i++) {
                String name = objs[i].getClass().getName();
                String[] split = name.split("\\.");
                int index = (split.length - 1);
                System.out.println( split[index] + ":" + objs[i].toString());
            }
        }
    }
}
